package com.txy.webmanagement.service;

import com.gitee.sunchenbin.mybatis.actable.command.PageResultCommand;
import com.gitee.sunchenbin.mybatis.actable.manager.common.BaseMysqlCRUDManager;
import com.txy.webmanagement.model.SysProduct;
import com.txy.webmanagement.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 产品管理接口
 *
 * @author wf
 * @date 2019-03-03$
 **/
@Service
public class SysProductService {
    @Autowired
    private BaseMysqlCRUDManager baseMysqlCRUDManager;


    public List<SysProduct> pageList(SysProduct pd) {
        PageResultCommand<SysProduct> ss = baseMysqlCRUDManager.query(pd);
        List<SysProduct> li = ss.getData();
        return li;
    }

    public SysProduct getOne(String searchId) {
        if (StringUtils.checkStringNotNull(searchId)) {
            SysProduct product = new SysProduct();
            product.setSearchId(searchId);
            PageResultCommand<SysProduct> ss = baseMysqlCRUDManager.query(product);
            if (ss.getData() != null && ss.getData().size() > 0) {
                return ss.getData().get(0);
            } else {
                return null;
            }
        } else {
            return null;
        }
    }

    public Boolean save() {
        SysProduct product = new SysProduct();
        Integer sq = baseMysqlCRUDManager.save(product);
        if (sq > 0) {
            return true;
        } else {
            return false;
        }

    }

    public Boolean update() {
        SysProduct product = new SysProduct();
        Integer sq = baseMysqlCRUDManager.save(product);
        if (sq > 0) {
            return true;
        } else {
            return false;
        }
    }


    public void delete(String searchId) {
        SysProduct product = getOne(searchId);
        if (product != null) {
            baseMysqlCRUDManager.delete(product);
        }
    }
}
